<?php
declare(strict_types=1);

namespace app\api\controller;

use app\BaseController;
use app\common\business\Sms as SmsBus;
class Sms extends BaseController
{
    public function code(): Object
    {
        $phone_number=input("param.phone_number","","trim");
        $data=[
            "phone_number"=>$phone_number
        ];
        try {
            validate(\app\api\validate\User::class)->scene("send_code")->check($data);
        }catch (\think\Exception\ValidateException $e){
            return show_Json(config("status.error"),$e->getError());
        }
        //调用 business 层
        if (SmsBus::sendCode($phone_number,config("qq.sms_length"))){
            return show_Json(config("status.success"),"发送验证码成功");
        }else{
            return show_Json(config("status.success"),"发送验证码失败");
        }
    }
}